package com.hxkcloud.nurse.utils;

import android.graphics.Bitmap;
import android.text.TextUtils;

import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.hxkcloud.nurse.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

import java.util.Calendar;

/**
 * Created by william_sun on 2016-07-15.
 * Description:
 */
public class ImageOptionUtils {
    private static ImageOptionUtils optionUtils = null;

    public static ImageOptionUtils getInstance() {
        synchronized (ImageOptionUtils.class) {
            if (optionUtils == null) {
                optionUtils = new ImageOptionUtils();
            }
        }
        return optionUtils;
    }

    public DisplayImageOptions getSimplePicOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.color.bg_imageloader)
                .showImageForEmptyUri(R.color.bg_imageloader)
                .showImageOnFail(R.color.bg_imageloader)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }


    public DisplayImageOptions getRoundPicOptions(int round) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.color.bg_imageloader)
                .showImageForEmptyUri(R.color.bg_imageloader)
                .showImageOnFail(R.color.bg_imageloader)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new RoundedBitmapDisplayer(round))//圆角
                //.displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //文章大图
    public DisplayImageOptions getArticlePicBigOptions(int round) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_wenzhang)
                .showImageForEmptyUri(R.drawable.default_wenzhang)
                .showImageOnFail(R.drawable.default_wenzhang)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
//                .displayer(new RoundedBitmapDisplayer(round))//圆角
                .build();
        return options;
    }

    //文章小图
    public DisplayImageOptions getArticlePicSmallOptions(int round) {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
//                .showStubImage(R.drawable.default_zixun)
//                .showImageForEmptyUri(R.drawable.default_zixun)
//                .showImageOnFail(R.drawable.default_zixun)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
//                .displayer(new RoundedBitmapDisplayer(round))//圆角
                .build();
        return options;
    }

    //科室头像
    public DisplayImageOptions getDepartmentHeadOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_departmenthead)
                .showImageForEmptyUri(R.drawable.default_departmenthead)
                .showImageOnFail(R.drawable.default_departmenthead)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //护士头像
    public DisplayImageOptions getNurseHeadOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_nurse)
                .showImageForEmptyUri(R.drawable.default_nurse)
                .showImageOnFail(R.drawable.default_nurse)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //护士头像
    public DisplayImageOptions getBannerOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.banner)
                .showImageForEmptyUri(R.drawable.banner)
                .showImageOnFail(R.drawable.banner)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //医生男头像
    public DisplayImageOptions getDoctorHeadMaleOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_doctor)
                .showImageForEmptyUri(R.drawable.default_doctor)
                .showImageOnFail(R.drawable.default_doctor)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //医生女头像
    public DisplayImageOptions getDoctorHeadFemaleOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_doctorw)
                .showImageForEmptyUri(R.drawable.default_doctorw)
                .showImageOnFail(R.drawable.default_doctorw)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //男患者50以下头像
    public DisplayImageOptions getMan20HeadOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_man20)
                .showImageForEmptyUri(R.drawable.default_man20)
                .showImageOnFail(R.drawable.default_man20)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //男患者50以上头像
    public DisplayImageOptions getMan50HeadOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_man50)
                .showImageForEmptyUri(R.drawable.default_man50)
                .showImageOnFail(R.drawable.default_man50)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //女患者50以下头像
    public DisplayImageOptions getWoman20HeadOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_woman20)
                .showImageForEmptyUri(R.drawable.default_woman20)
                .showImageOnFail(R.drawable.default_woman20)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //女患者50以上头像
    public DisplayImageOptions getWoman50HeadOptions() {
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.default_woman50)
                .showImageForEmptyUri(R.drawable.default_woman50)
                .showImageOnFail(R.drawable.default_woman50)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }

    //患者默认头像age:yyyy-MM-dd sex:0/1
    public DisplayImageOptions getPatientHeadOptions(String age, String sex) {
        int defaultHead = R.drawable.default_patient;
        if (TextUtils.isEmpty(age) || TextUtils.isEmpty(sex)) {
            defaultHead = R.drawable.default_patient;
        } else {
            boolean isYoung = true;
            if (!TextUtils.isEmpty(age)) {
                int ageYear = Integer.valueOf(age.split("-")[0]);
                Calendar calendar = Calendar.getInstance();
                int curYear = calendar.get(Calendar.YEAR);
                if (curYear - ageYear > 49) {
                    isYoung = false;
                } else {
                    isYoung = true;
                }
            }
            if (sex.equals("0")) {//male
                if (!isYoung) {
                    defaultHead = R.drawable.default_man50;
                } else {
                    defaultHead = R.drawable.default_man20;
                }
            } else {//female
                if (!isYoung) {
                    defaultHead = R.drawable.default_woman50;
                } else {
                    defaultHead = R.drawable.default_woman20;
                }
            }
        }
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(defaultHead)
                .showImageForEmptyUri(defaultHead)
                .showImageOnFail(defaultHead)
                .cacheInMemory(true)//
                .cacheOnDisk(true)//
                .bitmapConfig(Bitmap.Config.ARGB_8888)//
                .displayer(new FadeInBitmapDisplayer(300))//图片渐入动画
                .displayer(new SimpleBitmapDisplayer()) // default
                .build();
        return options;
    }
}
